#include <stdio.h>
#include <stdlib.h>
#include "f16.h"


float g_fValues[8] = {1235.0f, 1236.1f, 1237.01f, -1238.012f, 1239.0123f, 2236.01234f, 72230.012345f, 3677.0123456f};
uint32_t *g_puiValue = (uint32_t *)g_fValues;
f32Type *g_pf32Value = (f32Type *)g_fValues;
f16Type g_f16Value;


int main(void)
{
    for(int32_t i = 0; i < sizeof(g_fValues) / sizeof(g_fValues[0]); ++i)
    {
        g_f16Value = __float2half(g_fValues[i]);

        printf("ram hex: 0x%08X, single float: %16f, half float: %16f\r\n", g_puiValue[i], g_fValues[i], __half2float(g_f16Value));
        printf("single float sign: %d, exponent: %4d, fraction: 0x%06X\r\n", g_pf32Value[i].sign, g_pf32Value[i].exponent - 127, g_pf32Value[i].fraction);
        printf("half   float sign: %d, exponent: %4d, fraction: 0x%06X\r\n\n", g_f16Value.sign, g_f16Value.exponent - 15, g_f16Value.fraction);
    }

    return 0;
}

